package com.zpeb.pdd.exception;

import com.zpeb.pdd.utils.Msg;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Auther: qiuzp
 * @Date: 2019/1/13 0013 1:18
 * @Description:
 */
@RestControllerAdvice
public class ExceptionAdvice {

    private org.slf4j.Logger logger = LoggerFactory.getLogger(ExceptionAdvice.class);

//    private static final Logger log = Logger.getLogger(String.valueOf(ExceptionAdvice.class));

//    @ResponseStatus(HttpStatus.NOT_FOUND)
//    @ExceptionHandler(NoHandlerFoundException.class)
//    public Msg handlerNotFoundException(NoHandlerFoundException e) {
//        e.printStackTrace();
//        return Msg.fail().add("msg", "not found");
//    }

    @ExceptionHandler({Exception.class})
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public Msg Exception(Exception e) {
        String erorr = e.toString();
        logger.error(erorr);
        e.printStackTrace();
        return Msg.fail().add("msg", "服务器内部错误!我们会尽快处理,谢谢").add("error",erorr);
    }

}
